//----------------------------------------------------------------------------
// SQL queries
//----------------------------------------------------------------------------
var createTableApotheken = 'CREATE TABLE IF NOT EXISTS apotheken(id INTEGER PRIMARY KEY, name TEXT);'; 

var createTableHHrecepten = 'CREATE TABLE IF NOT EXISTS hhrecepten(' +
'id INTEGER PRIMARY KEY, '+ 
'date_time TEXT, '+
'name TEXT, '+      //tfNaam
'initials TEXT, '+  //tfInitialen
'bdate TEXT, '+     //tfGebDatum
'street TEXT, '+    //tfStraat
'postcode TEXT, '+  //tfPostcode
'place TEXT, '+     //tfPlaats
'phone TEXT, '+     //tfTelefoon
'medicine TEXT, '+  //tfMedicijn
'dose TEXT, '+      //tfMg
'number TEXT, '+    //tfAantal
'usage TEXT, '+     //tfGebruik
'pharmacy TEXT, '+  //tfApotheek
'image BLOB);'; 



//----------------------------------------------------------------------------
// Apotheken DB
//----------------------------------------------------------------------------
var apothekendb = Ti.Database.open('apotheken');
apothekendb.close();

function setupApothekenDB() {
	log("Tabel 'apotheken' initialiseren");
	apothekendb = Ti.Database.open('apotheken');
	apothekendb.execute('DROP TABLE IF EXISTS apotheken;');
	apothekendb.execute(createTableApotheken);
	apothekendb.close();	
}

function populateApothekenDB() {
	log("Tabel 'apotheken' vullen");
	apothekendb = Ti.Database.open('apotheken');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek Malberg');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Nazareth');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Mosae Forum');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Amby');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Centrum Apotheek Schoepp');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek Romkens');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Straver');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'BENU Apotheek Heugem');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Transmurale Apotheek Maastricht');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Martens');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Medsen Apotheek Wijck');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek America');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek Heer');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek Scharwijerveld');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek Sint Pieter');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek ten Horn');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Apotheek van Thoor');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'BENU Apotheek De Heerderrein');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek Annadal');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Mediq Apotheek De Heeg');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Service Apotheek Caberg');
	apothekendb.execute('INSERT INTO apotheken (name) VALUES (?)', 'Valbereidingsapotheek Maastricht');
	//Checks
   var rows = apothekendb.execute('SELECT * FROM apotheken'); 
   log('Aantal apotheken: ' + rows.getRowCount());
	//Close
	apothekendb.close();
}


//----------------------------------------------------------------------------
// Herhaalrecepten historie DB
//----------------------------------------------------------------------------
log("Database 'hhrecepten' initialiseren");   
var hhreceptendb = Ti.Database.open('hhrecepten');
hhreceptendb.close();

function setupHHReceptenDB() {
   log("Tabel 'hhrecepten' initialiseren");   
   hhreceptendb = Ti.Database.open('hhrecepten');
   hhreceptendb.execute(createTableHHrecepten);
   hhreceptendb.close();
}